import { config } from '../../config.js'
  
const tips = {
	1: '抱歉出现了一个错误',
	1003: '网络请求参数传入错误',
	1004: '服务器异常，请联系联系客服'
}

export class HTTP {
	request({url, data = {}}) {
		const promise = new Promise((resolve, reject) => {
				this._request(url,data,resolve,reject)
		})
		return promise
	}
	_request(url, data, resolve, reject) {
		uni.showLoading()
		uni.request({
			url: config.httpUrl + url,
			method: "POST",
			header:{'Content-Type':'application/json'},	         
			data: data,
			success: (res) => {
				uni.hideLoading()
				const code = res.data.code
				const data = res.data.data
				if (code == 1001) {
					resolve(data)
				} else {
					this._shwo_error(res.data.message)
				}
			},
			fail: err => {
				uni.hideLoading()
				reject() 
				this._shwo_error()
			}
		})
	}
	// 添加下划线的方法，视为私有方法
	_shwo_error(code) {
		uni.showToast({
			title: code || '发生了错误',
			icon: "none"
		})
	}
}
